package com.aqa.concurrent;

import org.junit.Test;

import java.util.concurrent.*;
import java.util.stream.IntStream;

public class CountDownLatchTest {


    @Test
    public void testCd() throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(2);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(10, 10, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(10));
        IntStream.range(1, 3).forEach(i -> {
            pool.submit(() -> {
                try {
                    System.out.println("------ 线程启动：" + Thread.currentThread().getName() + " ------ ");
                    latch.await();
                    System.out.println("------ 线程阻塞停止：" + Thread.currentThread().getName() + " ------ ");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        });

        latch.countDown();
        latch.countDown();
//        latch.countDown();
//        latch.countDown();
//        latch.countDown();
        Thread.currentThread().join();
    }
}
